/* Anhui Wanyun Information Technology Co., Ltd. */
package com.liliudong.pinkyponk.biz.base;

import cn.hutool.core.collection.CollectionUtil;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Convert基类
 *
 * @author Liudong.li
 * @version 1.0
 * @date 2021-10-23 18:53
 */

public interface BaseConvert<Entity, Req, Res> {

    /**
     * entityToRes
     *
     * @param e
     * @return
     */
    Res entityToRes(Entity e);

    /**
     * reqToRes
     *
     * @param r
     * @return
     */
    Res reqToRes(Req r);

    /**
     * resToEntity
     *
     * @param r
     * @return
     */
    Entity resToEntity(Res r);

    /**
     * reqToEntity
     *
     * @param r
     * @return
     */
    Entity reqToEntity(Req r);

    /**
     * resToReq
     *
     * @param r
     * @return
     */
    Req resToReq(Res r);

    /**
     * entityToReq
     *
     * @param e
     * @return
     */
    Req entityToReq(Entity e);

    /**
     * entityListToResList
     *
     * @param entities
     * @return
     */
    default List<Res> entityListToResList(Collection<Entity> entities) {
        if (CollectionUtil.isEmpty(entities)) {
            return List.of();
        }
        return entities.stream().map(this::entityToRes).collect(Collectors.toList());
    }

}
